package org.soenea.doitall.domain.model.user.mapper;

import java.sql.SQLException;

import org.dsrg.soenea.domain.MapperException;
import org.dsrg.soenea.domain.mapper.LostUpdateException;
import org.dsrg.soenea.domain.mapper.IOutputMapper;
import org.soenea.doitall.domain.model.user.data.*;
import org.soenea.doitall.domain.model.user.*;

public class UserOutputMapper implements IOutputMapper<Long, User> {
	public void update(User u) throws MapperException, LostUpdateException {
		try {
			int count = UserTDG.update(u.getId(), u.getVersion(), u.getUserName(), u.getFirstName(), u.getLastName(), u.getPassword(), u.getGroupID(), u.isAdmin());
			if (count == 0)
				throw new LostUpdateException("User " + u.getId() + " has already been updated.");
		} catch(SQLException e) {
			throw new MapperException(e);
		}
	}
	
	public void insert(User u) throws MapperException, LostUpdateException {
		
		
		try {
			UserTDG.insert(u.getId(),u.getUserName(),u.getFirstName(),u.getLastName(),u.getPassword(),u.getGroupID(),u.getVersion(),u.isAdmin());
		} catch (final SQLException e) {
			throw new MapperException(e);
		}
	
	}

	@Override
	public void delete(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cascadeInsert(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cascadeUpdate(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cascadeDelete(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateInsert(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateUpdate(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void validateDelete(User d) throws MapperException {
		// TODO Auto-generated method stub
		
	}
}
